import request from "@/utils/request"
import { WECHAT_CODE_TO_SESSION_KEY } from "@/config/storage"

/**
 * code 换取 openid
 * @param code
 */
export function codeToSession(code: string) {
  return request.get('/user-logins/code-to-session', { params: { code } })
}

/**
 * 用户登录
 * @param data
 */
export function userLogin(params: any) {
  // @ts-ignore
  return request.get('/user-logins/login-mini-program', { params }, { isAuth: false })
}


/**
 * 获取用户信息
 * @param data
 */
export function decryptData(params: any) {
  return request.get('/user-logins/decrypt-data', { params })
}

/**
 * 获取用户信息
 * @param data
 */
export function getPhoneNumber(data: any) {
  return request.get('/user-logins/decrypt-data',{
    params: {
      ...data,
      codeToSessionKey: wx.getStorageSync(WECHAT_CODE_TO_SESSION_KEY)
    }
  })
}

/**
 * 获取用户信息
 */
export function getUserInfo() {
  // @ts-ignore
  return request.get('/users/get-info', {}, { isAuth: false  })
}

/**
 * 获取用户收益
 */
export function getUserCommissions() {
  // @ts-ignore
  return request.get('/user-commissions/get', {}, { isAuth: false  })
}

/**
 * 更新会员基础信息
 */
export function updateUserInfo(data) {
  return request.put(`/users/update-info-by-id`, data)
}

/**
 * 用户注册
 * @param data
 */
export function userReg(data: any) {
  return request.post(`/users/register-user-info`, data)
}

/**
 * 同步用户信息
 */
export function asyncWechatInfo(data) {
  return request.put('/users/async-wechat-info', data)
}


/**
 * 获取会员数量
 */
export function getMemberCount() {
  return request.get('/users/count-vip-pay')
}

/**
 * 获取会员资格
 */
export function getMemberPermanent() {
  return request.get('/users/permanent-vip-pay')
}

// /**
//  * 终身会员资格
//  */
// export function payPermanentVip() {
//   return request.get({
//     url: '/users/permanent-vip-pay'
//   })
// }


/* ------------------------------------------------------- 购物车 ------------------------------------------------------- */
/**
 * 分页获取购物车
 */
export function getCartPage(params) {
  // @ts-ignore
  return request.get('/users/get-shop-cart-page', { params }, { isAuth: false  })
}

/**
 * 获取购物车列表
 */
export function getCartList(params) {
  return request.get('/users/get-shop-cart-list', { params })
  // return request.request({
  //   url: '/users/get-shop-cart-list',
  //   data
  // })
}

/**
 * 添加商品到购物车
 */
export function addCart(data) {
  return request.post('/users/add-shop-cart', data)
}

/**
 * 获取单条购物车信息
 */
export function getCartInfo(id) {
  return request.get(`/users/get-shop-cart-by-id/${id}`)
}

/**
 * 批量删除购物车商品
 */
export function delBatchCart(data) {
  return request.delete('/users/del-shop-cart', data)
}

/**
 * 更新购物车
 */
export function updateCart(data) {
  return request.put('/users/update-shop-cart-by-id', data)
}

/**
 * 更新购物车数量
 */
export function updateCartNumber(data) {
  return request.put('/users/update-shop-cart-number', data)
}
/* ------------------------------------------------------- 购物车 ------------------------------------------------------- */



/* ------------------------------------------------------- 收货地址 ------------------------------------------------------- */

/**
 * 分页获取收货地址
 */
export function getAddressPage() {
  return request.get('/users/get-address-page')
}

/**
 * 获取全部收货地址
 */
export function getAddressList() {
  return request.get('/users/get-address-list')
}

/**
 * 添加收货地址
 */
export function addAddress(data) {
  return request.post('/users/add-address', data)
}

/**
 * 编辑收货地址
 */
export function updateAddress(data) {
  return request.put('/users/update-address-by-id', data)
}


/**
 * 获取地址信息
 */
export function getAddressInfo(id) {
  return request.get(`/users/get-address-by-id/${id}`)
}

/**
 * 设置默认地址
 */
export function setDefaultAddress(data) {
  return request.put('/users/set-default-address', data)
}

/**
 * 删除地址信息
 */
export function delAddressInfo(id) {
  return request.delete(`/users/del-address-by-id/${id}`)
}

/* ------------------------------------------------------- 收货地址 ------------------------------------------------------- */






/* ------------------------------------------------------- 用户钱包 ------------------------------------------------------- */
/**
 * 分页获取用户钱包（钱包记录）
 */
export function getWalletPage(data) {
  return request.request({
    url: '/users/get-wallet-detail-page',
    data
  })
}

/**
 * 用户充值
 */
export function userCharges(data) {
  return request.post('/user-charges/charge', data)
}

/**
 * 购买会员
 */
export function buyMember(data) {
  return request.post('/user-charges/buy-vip', data)
}
/* ------------------------------------------------------- 用户钱包 ------------------------------------------------------- */






/* ------------------------------------------------------- 用户积分 ------------------------------------------------------- */

/**
 *  获取积分配置
 */
export function getScoreConfig() {
  return request.get('/user-scores/get-score-config')
}


/**
 *  获取签到信息
 */
export function getSignScore() {
  return request.get('/user-scores/get-sign-score')
}

/**
 *  积分签到
 */
export function addSignScore() {
  return request.post('/user-scores/sign-score')
}


/**
 *  分页获取积分记录
 */
export function getScorePage(params) {
  return request.get('/user-scores/get-detail-page', { params })
}

/**
 *  积分中心
 */
export function getUserScore() {
  return request.get('/user-scores/user-score')
}

/* ------------------------------------------------------- 用户积分 ------------------------------------------------------- */






/* ------------------------------------------------------- 优惠券 ------------------------------------------------------- */

/**
 * 分页获取优惠券（我的优惠券）
 */
export function getMyCouponPage(params) {
  return request.get('/users/get-my-coupon-page', { params })
}

/**
 * 分页获取优惠券（可领取优惠券）
 */
export function getCouponPage(params) {
  return request.get('/users/get-coupon-page',{ params })
}

/**
 * 领取优惠券
 */
export function addCoupon(data) {
  return request.post('/users/add-coupon', data)
}

/* ------------------------------------------------------- 优惠券 ------------------------------------------------------- */





/* ------------------------------------------------------- 佣金 ------------------------------------------------------- */

/**
 * 我的佣金
 */
export function getCommission() {
  return request.get('/user-commissions/get')
}

/**
 * 佣金记录
 */
export function getCommissionRecordPage(params) {
  return request.get('/user-commissions/get-detail-page', { params })
}

/**
 * 提现记录
 */
export function getCashRecordPage(params) {
  return request.get('/user-commissions/get-draw-detail-page', { params })
}

/**
 * 佣金提现到微信
 */
export function applyCommissionCash(data) {
  return request.post('/users/apply-draw-to-wx', data)
}

/**
 * 佣金提现到钱包
 */
export function applyDrawToWallet(data) {
  return request.post('/users/apply-draw-to-wallet', data)
}

/**
 * 获取我的团队
 */
export function getGisciplePage(params) {
  return request.get('/users/get-disciple-page', { params })
}

/**
 * 获取我的团队贡献
 */
export function getGiscipleDetailPage(params) {
  return request.get('/user-commissions/get-disciple-detail-page', { params })
}

/**
 * 获取当前月的佣金
 */
export function getCurrentMonthCommission() {
  return request.get('/user-commissions/come-in-this-month')
}


/* ------------------------------------------------------- 佣金 ------------------------------------------------------- */
